package base.service.impl;

import bean.UserAddress;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import service.OrderService;
import service.UserService;

import java.util.List;
import java.util.Objects;

@Service
public class OrderServiceImpl implements OrderService {

    /**
     * 配置dubbo，自动从注册中心发现服务
     * url：采用dubbo直连的方式直接调用提供方
     * loadbalance：负载均衡
     *      roundrobin-轮询
     *      random-权重
     *
     */
    //@Reference(url = "127.0.0.1:20882")
    @Reference(loadbalance = "random",timeout = 1000)
    private UserService userService;

    @Override
    public List<UserAddress> initOrder(String userId) {
        System.out.println("用户id：" + userId);
        //1、查询用户的收货地址
        List<UserAddress> addressList = userService.getUserAddressList(userId);
        if (Objects.isNull(addressList)) {
            return null;
        }
        for (UserAddress userAddress : addressList) {
            System.out.println(userAddress.getUserAddress());
        }
        return addressList;
    }
}
